package sinpleFactory.order;

import sinpleFactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * @author feng
 * @Date 2021/10/14 17:42
 */
public class OrderPizza {

    //定义一个简单工场列表
    SimpleFactory factory;
    Pizza pizza = null;

    //设置构造器
    public OrderPizza(SimpleFactory factory){
          setFactory(factory);
    }


    public void setFactory(SimpleFactory factory) {
        String orderType = "";
        this.factory = factory;
        do {
            orderType = getType();
            //原材料业务
            pizza = this.factory.createPizza(orderType);
            //订单相关业务
            if (pizza != null) {
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("运行失败");
                break;
            }

        } while (true);

    }


    public String getType() {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("输入订购的类型");
            String str = reader.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
